Skip to content

Latest commit

 

History

History
32 lines (23 loc) · 1.21 KB

File metadata and controls

32 lines (23 loc) · 1.21 KB

Unit Testing View Controllers in Swift

TODO

  • Provide examples for unit testing view controllers.

What To Unit Test in View Controllers?

Appropriate aspects to test in View Controllers unit tests:

  • Is UILabel text correct?
  • Is the number of UITableView rows correct?
  • Is UIButton enabled?

Inappropriate aspects to test in View Controllers unit tests:

  • UILabel text color, font, and size.
  • UITableView background color.
  • UIButton autolayout constraints.

How to Write Testable View Controllers?

View controllers are considered testable if they are:

  • Passive:
    • They delegate actions to appropriate dependencies, such as a presenter or a view model.
    • They focus solely on rendering the UI.
  • Isolated from their dependencies:
    • They don't directly retrieve data from the model.
    • They aren't responsible for updating themselves based on the model.

MVVM and MVP are patterns that facilitate achieving these characteristics.

References